home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Developer's Kit 1996
/
Delphi Developer's Kit 1996.iso
/
power
/
source8
/
bimage.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-12-22
|
8KB
|
310 lines
{Part of Imagelib VCL/DLL Library.
Written by Jan Dekkers and Kevin Adams}
unit Bimage;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, FileCtrl, TMULTI, VBXCtrl, Switch, Spin,
Buttons, BFullscr, Menus, Babout;
type
TForm1 = class(TForm)
DriveComboBox1: TDriveComboBox;
DirectoryListBox1: TDirectoryListBox;
FileListBox1: TFileListBox;
MultiImage1: TMultiImage;
Convert: TBitBtn;
QualitySpin: TSpinEdit;
Smoothspin: TSpinEdit;
QualityLabel: TLabel;
SmoothLabel: TLabel;
GroupBox1: TGroupBox;
res4: TRadioButton;
res24: TRadioButton;
res8: TRadioButton;
GroupBox2: TGroupBox;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
DitherOneNo: TRadioButton;
DitherOneYes: TRadioButton;
DitherTwoNo: TRadioButton;
DitherTwoYes: TRadioButton;
Dither24Bit: TRadioButton;
MainMenu1: TMainMenu;
N1: TMenuItem;
E1: TMenuItem;
A1: TMenuItem;
ComboBox1: TComboBox;
Sstretch: TCheckBox;
GroupBox3: TGroupBox;
CTOJPEG: TRadioButton;
CTOBMP: TRadioButton;
Label1: TLabel;
FileListBox2: TFileListBox;
DirectoryListBox2: TDirectoryListBox;
DriveComboBox2: TDriveComboBox;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure DriveComboBox1Change(Sender: TObject);
procedure DirectoryListBox1Change(Sender: TObject);
procedure FileListBox1Change(Sender: TObject);
procedure SstretchOnOff(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure resClick(Sender: TObject);
procedure DitherClick(Sender: TObject);
procedure MultiImage1Click(Sender: TObject);
procedure E1Click(Sender: TObject);
procedure A1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ComboBox1Change(Sender: TObject);
procedure ConvertClick(Sender: TObject);
procedure DirectoryListBox2Change(Sender: TObject);
procedure DriveComboBox2Change(Sender: TObject);
procedure FileListBox2Change(Sender: TObject);
procedure QualitySpinChange(Sender: TObject);
procedure SmoothspinChange(Sender: TObject);
private
function NameOnly(PName : string) : string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{update the drive of DirectoryListBox1 with the drive of DriveComboBox1}
procedure TForm1.DriveComboBox1Change(Sender: TObject);
begin
DirectoryListBox1.Drive := DriveComboBox1.Drive;
end;
{update the directory of FileListBox1 with the directory of FileListBox1}
procedure TForm1.DirectoryListBox1Change(Sender: TObject);
begin
FileListBox1.Directory := DirectoryListBox1.Directory;
end;
{Display the image of the FileListBox1.filename}
procedure TForm1.FileListBox1Change(Sender: TObject);
begin
{set hourglass cursor}
screen.cursor:=crHourGlass;
try
{display an image using the vcl}
MultiImage1.imagename:=FileListBox1.filename;
finally
{set default cursor}
screen.cursor:=crDefault;
end;
end;
procedure TForm1.FileListBox2Change(Sender: TObject);
begin
{set hourglass cursor}
screen.cursor:=crHourGlass;
try
{display an image using the vcl}
MultiImage1.imagename:=FileListBox2.filename;
finally
{set default cursor}
screen.cursor:=crDefault;
end;
end;
{set strech mode}
procedure TForm1.SstretchOnOff(Sender: TObject);
begin
MultiImage1.stretch:=Sstretch.Checked;
end;
{what we do on create}
procedure TForm1.FormCreate(Sender: TObject);
begin
{set the value of the QualitySpin to the value of JPegSaveQuality}
QualitySpin.value:=MultiImage1.JPegSaveQuality;
{set the value of the Smoothspin to the value of JPegSaveSmooh}
Smoothspin.value:=MultiImage1.JPegSaveSmooth;
end;
{Set the jpeg resolution to either 16, 256 or true color in the vcl}
procedure TForm1.resClick(Sender: TObject);
begin
{set jpeg show resolution to 4 bit 16 color}
if res4.checked then MultiImage1.JPegResolution:=4;
{set jpeg show resolution to 8 bit 256 color}
if res8.checked then MultiImage1.JPegResolution:=8;
{set jpeg show resolution to 24 bit true color}
if res24.checked then MultiImage1.JPegResolution:=24;
end;
{Set the jpeg dither in the vcl}
procedure TForm1.DitherClick(Sender: TObject);
begin
{set the jpeg show dither to none (best choice for true color 24 bit}
if Dither24Bit.checked then MultiImage1.JPegDither:=0;
{set the jpeg show dither to one pass none}
if DitherOneNo.checked then MultiImage1.JPegDither:=1;
{set the jpeg show dither to one pass dithered (best choice for 16 colors)}
if DitherOneYes.checked then MultiImage1.JPegDither:=2;
{set the jpeg show dither to one pass none}
if DitherTwoNo.checked then MultiImage1.JPegDither:=3;
{set the jpeg show dither to two pass dithered (best choice for 256 colors)}
if DitherTwoYes.checked then MultiImage1.JPegDither:=4;
end;
{show fullscreen}
procedure TForm1.MultiImage1Click(Sender: TObject);
begin
{copy image to fullscreen image}
FullSlide.MultiImage1.Picture.Graphic:=MultiImage1.Picture.Graphic;
{show the image fulscreen}
FullSlide.showmodal;
end;
{exit the program}
procedure TForm1.E1Click(Sender: TObject);
begin
close;
end;
{about box}
procedure TForm1.A1Click(Sender: TObject);
begin
{Copy the image to the image of he about box}
AboutBox.MultiImage1.Picture.Graphic:=MultiImage1.Picture.Graphic;
{show the about box}
AboutBox.showmodal;
end;
{what to do on exit}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
{}
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
FileListBox1.Mask:=ComboBox1.text;
FileListBox1.Update;
end;
{return filename only. no path, no extension}
function TForm1.NameOnly(PName : string) : string;
var
DtP : Byte;
function JName(PName : string) : string;
var
I : Word;
const
DDSet : set of Char = ['\', ':', #0];
begin
I := Succ(Word(Length(PName)));
repeat
Dec(I);
until (PName[I] in DDSet) or (I = 0);
JName := Copy(PName, Succ(I), 64);
end;
begin
PName := JName(PName);
DtP := Pos('.', PName);
if DtP > 0 then
PName := Copy(PName, 1, DtP-1);
NameOnly := PName;
end;
{The actual conversion}
procedure TForm1.ConvertClick(Sender: TObject);
var i : integer;
pTempExt : string[4];
pExtension : string[4];
pName : string[13];
pPath : string[100];
toTemp : string;
frTemp : string;
begin
Label3.CapTion:='';
if CTOJPEG.Checked then
pTempExt:='.JPG'
else
pTempExt:='.BMP';
for i:=0 to FileListBox1.items.count-1 do begin
if FileListBox1.Selected[i] then begin
pExtension:=UpperCase(ExtractFileExt(FileListBox1.Items.Strings[i]));
pName:=UpperCase(NameOnly(FileListBox1.Items.Strings[i]));
pPath:=UpperCase(DirectoryListBox2.Directory);
toTemp:=pPath+'\'+pName+pTempExt;
frTemp:=UpperCase(DirectoryListBox1.Directory+'\'+FileListBox1.Items.Strings[i]);
{set hourglass cursor}
screen.cursor:=crHourGlass;
try
if CTOJPEG.Checked then begin
MultiImage1.imagename:=frTemp;
MultiImage1.SaveAsJpg(toTemp)
end else begin
MultiImage1.imagename:=frTemp;
MultiImage1.Picture.SaveToFile(toTemp);
end;
finally
{set default cursor}
screen.cursor:=crDefault;
FileListBox2.UpDate;
end;
end;
Label3.CapTion:='DONE';
end;
end;
procedure TForm1.DirectoryListBox2Change(Sender: TObject);
begin
FileListBox2.Directory := DirectoryListBox2.Directory;
end;
procedure TForm1.DriveComboBox2Change(Sender: TObject);
begin
DirectoryListBox2.Drive := DriveComboBox2.Drive;
end;
procedure TForm1.QualitySpinChange(Sender: TObject);
begin
MultiImage1.JpegSaveQuality:=QualitySpin.Value;
end;
procedure TForm1.SmoothspinChange(Sender: TObject);
begin
MultiImage1.JpegSaveSmooth:=Smoothspin.Value;
end;
end.